/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						      color_sum.h

	$Header: /resource_editor/color_sum.h $

	$NoKeywords: $

 ************************************************************************/

#ifndef COLOR_SUM_H_INCLUDED
#define COLOR_SUM_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

struct t_color_count;
struct t_pixel_24;
//------------------------------------------------------------
// class to record the color statistics about a 3D region of 
// color space.
//------------------------------------------------------------
class t_color_sum
{
public:
	t_color_sum();
	
	t_pixel_24 get_average() const;  // find the average color for the volume
	int        get_count() const;    // get the total # of pixels
	__int64    get_delta() const;    // get partial error - basically, the part
	                                 // that changes when splitting the volume
	__int64    get_variance() const; // get the most recently calculated variance
	                                 // (total color error) for the volume.
	void       set_variance();		 // calculate the variance.
	t_color_sum& operator += ( t_color_count const& point ); // add a color point
	t_color_sum& operator -= ( t_color_count const& point ); // remove a color point

protected:
	int        m_count;       // total # of pixels
	__int64    m_variance;    // total color error for the volume
	int        m_sum[3];      // sum of color values for each channel
	__int64	   m_square_sum;  // sum of squares of all 3 color values
};

//------------------------------------------------------------
// inlines for t_color_sum
//------------------------------------------------------------
inline int t_color_sum::get_count() const
{
	return m_count;
}

inline __int64 t_color_sum::get_variance() const
{
	return m_variance;
}

inline void t_color_sum::set_variance() 
{
	m_variance = m_square_sum + get_delta();
}

#endif // COLOR_SUM_H_INCLUDED